package com.shilun.springboot.hello_demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.shilun.springboot.hello_demo.dao.UserDao;
import com.shilun.springboot.hello_demo.entity.User;
import com.shilun.springboot.hello_demo.mapper.UserMapper;

@Service
public class UserService {
	@Autowired
	 private UserDao userDao;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private UserMapper userMapper;
	
	public void createUser(String name, Integer age) {
		System.out.println("createUser");
		//jdbcTemplate.update("insert into users(id,name,age) value(null,?,?);", name, age);
		userMapper.createUser(name, age);
		System.out.println("创建用户成功...");
	}
	 
	public User findUser(Integer id) {
		System.out.println("findUser,id="+id);
		User findOne = userDao.findOne(id);
		System.out.println("findUser,id="+id+",user="+findOne);
		return findOne;
	}
	public User findUserByName(String name) {
		System.out.println("findUser,name="+name);
		User findOne = userMapper.findUser(name);
		System.out.println("findUser,name="+name+",user="+findOne);
		
		return findOne;
	}
}
